﻿using System;
using System.Collections.Generic;
using System.Linq;
using Gp.Scripts.Core;
using Sirenix.Utilities;
using UnityEngine;

namespace Gp.Scripts.Core {

    [Serializable]
    public class SerializedTutorialModel : ISerializedModel {
        [SerializeField] public string[] triggeredKeys;

        public SerializedTutorialModel() { }
        public SerializedTutorialModel(string[] triggeredKeys) {
            this.triggeredKeys = triggeredKeys;
        }
    }

    public class TutorialModel : PersistentModel<SerializedTutorialModel> {
        protected override void OnInit() { }

        /// <summary>
        /// 已经触发过的教程
        /// </summary>
        private readonly HashSet<string> _triggeredKey = new();

        public override ISerializedModel OnSave() {
            return new SerializedTutorialModel(_triggeredKey.ToArray());
        }


        protected override void OnLoad(SerializedTutorialModel data) {
            _triggeredKey.Clear();
            _triggeredKey.AddRange(data.triggeredKeys);
        }


        public bool TryTriggered(string tutorialKey) {
            if (_triggeredKey.Contains(tutorialKey)) {
                return false;
            }

            _triggeredKey.Add(tutorialKey);
            return true;
        }
    }
}